﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Tasks.Common;

namespace Tasks.API
{
    public class APIConfig
    {


        /// <summary>
        /// 读取配置文件的值 properties.config
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string ReadConfigKey(string key)
        {
            try
            {
                string path = AppDomain.CurrentDomain.BaseDirectory + "\\api.config";

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(path);

                string xpath = string.Format("/settings/add[@key='{0}']", key);
                XmlNode node = xmlDoc.SelectSingleNode(xpath);

                if (node != null)
                    return node.Attributes["value"].Value;
                else
                    return "";
            }
            catch (Exception ex)
            {
                Log.WriteLog(ex);
                return "";            
            }
        }
    }
}
